home *** CD-ROM | disk | FTP | other *** search
/ Borland JBuilder 6 / jbuilder6.iso / Taiji Applet Pack v2.7 / MenuFrame2 / MenuFrame2.class (.txt) < prev    next >
Encoding:
Java Class File  |  2001-11-06  |  12.2 KB  |  528 lines

  1. import java.applet.Applet;
  2. import java.applet.AudioClip;
  3. import java.awt.Color;
  4. import java.awt.Component;
  5. import java.awt.Dialog;
  6. import java.awt.Frame;
  7. import java.awt.Insets;
  8. import java.awt.LayoutManager;
  9. import java.awt.Menu;
  10. import java.awt.MenuBar;
  11. import java.awt.MenuComponent;
  12. import java.awt.MenuItem;
  13. import java.awt.event.MouseEvent;
  14. import java.awt.event.MouseListener;
  15. import java.awt.event.WindowEvent;
  16. import java.awt.event.WindowListener;
  17. import java.net.MalformedURLException;
  18. import java.net.URL;
  19. import java.net.URLEncoder;
  20. import java.util.Enumeration;
  21. import java.util.Hashtable;
  22.  
  23. public class MenuFrame2 extends Applet implements MouseListener, WindowListener {
  24.    private String[] url;
  25.    private String[] text;
  26.    private String target;
  27.    // $FF: renamed from: wi int
  28.    private int field_0;
  29.    // $FF: renamed from: he int
  30.    private int field_1;
  31.    public boolean hand = true;
  32.    private AudioClip sound;
  33.    public AudioClip clicSound;
  34.    private boolean loopSound;
  35.    public int pause = 200;
  36.    // $FF: renamed from: X0 int
  37.    int field_2;
  38.    // $FF: renamed from: Y0 int
  39.    int field_3;
  40.    MenuBar pop;
  41.    Dialog dialog;
  42.    Color textColor;
  43.    Color enterTextColor;
  44.    Color backColor;
  45.    Color enterBackColor;
  46.    Color borderColor;
  47.    int borderSize;
  48.    Hashtable table;
  49.    int maxWidth;
  50.    int maxHeight;
  51.    boolean isActive;
  52.    int dialogWidth = 250;
  53.    int dialogHeight = 200;
  54.  
  55.    public String getAppletInfo() {
  56.       return "Name: MenuFrame2\r\nAuthor: Taiji Software";
  57.    }
  58.  
  59.    public void register() {
  60.       try {
  61.          URL u = new URL("http://www.taijisoftware.com");
  62.          ((Applet)this).getAppletContext().showDocument(u, "_blank");
  63.       } catch (Exception e) {
  64.          System.out.println(e);
  65.          this.stop();
  66.       }
  67.    }
  68.  
  69.    public void init() {
  70.       String codeBase = null;
  71.  
  72.       try {
  73.          codeBase = (new URL(((Applet)this).getCodeBase().toString())).getHost();
  74.          System.out.println("Copyright 1999, 2001 Taiji Software(tm)\nYour domain name is : " + codeBase);
  75.          codeBase = codeBase.toUpperCase();
  76.       } catch (Exception var16) {
  77.       }
  78.  
  79.       if (!((Applet)this).getCodeBase().toString().toUpperCase().startsWith("FILE") || ((Applet)this).getParameter("debug") != null) {
  80.          String regCode = ((Applet)this).getParameter("registration_code");
  81.          if (regCode == null) {
  82.             regCode = ((Applet)this).getParameter("reg_domain");
  83.             if (regCode == null) {
  84.                this.register();
  85.             } else {
  86.                if (regCode.length() == codeBase.length() + 4 && !codeBase.startsWith("WWW.")) {
  87.                   codeBase = "WWW." + codeBase;
  88.                } else if (regCode.length() == codeBase.length() - 4 && codeBase.startsWith("WWW.")) {
  89.                   codeBase = codeBase.substring(4);
  90.                }
  91.  
  92.                char[] chars = new char[codeBase.length()];
  93.                codeBase.getChars(0, codeBase.length(), chars, 0);
  94.                String key = new String("haricot");
  95.                char[] chars2 = new char[key.length()];
  96.                key.getChars(0, key.length(), chars2, 0);
  97.  
  98.                for(int i = 0; i < codeBase.length(); ++i) {
  99.                   int j;
  100.                   if (i >= key.length()) {
  101.                      j = i - key.length() * (i / key.length());
  102.                   } else {
  103.                      j = i;
  104.                   }
  105.  
  106.                   chars[i] += chars2[j];
  107.                   chars[i] = (char)(chars[i] - chars[i] / 26 * 26 + 97);
  108.                }
  109.  
  110.                String res = new String(chars);
  111.                if (!res.equalsIgnoreCase(regCode)) {
  112.                   this.register();
  113.                }
  114.             }
  115.          } else if (!regCode.equals("settevercsedegnamiaj") && !regCode.equals("8078")) {
  116.             this.register();
  117.          }
  118.       }
  119.  
  120.       this.getParameters();
  121.       ((Component)this).setBackground(this.getColor("background_color"));
  122.  
  123.       for(int n = 0; ((Applet)this).getParameter("text" + Integer.toString(n + 1)) != null; ++n) {
  124.       }
  125.  
  126.       String s = ((Applet)this).getParameter("frame_title");
  127.       if (s == null) {
  128.          s = "Site map";
  129.       }
  130.  
  131.       Frame f = new Frame();
  132.       this.dialog = new Dialog(f, s);
  133.       this.dialog.setLayout((LayoutManager)null);
  134.       this.dialog.addWindowListener(this);
  135.       s = ((Applet)this).getParameter("frame_X");
  136.       int X;
  137.       if (s != null) {
  138.          X = Integer.parseInt(s);
  139.       } else {
  140.          X = 100;
  141.       }
  142.  
  143.       s = ((Applet)this).getParameter("frame_Y");
  144.       int Y;
  145.       if (s != null) {
  146.          Y = Integer.parseInt(s);
  147.       } else {
  148.          Y = 100;
  149.       }
  150.  
  151.       this.dialog.setBounds(X, Y, 200, 200);
  152.       if (((Applet)this).getParameter("frame_color") != null) {
  153.          this.dialog.setBackground(this.getColor("frame_color"));
  154.       }
  155.  
  156.       this.dialog.show();
  157.       Insets insets = this.dialog.getInsets();
  158.       this.field_2 = insets.left;
  159.       this.field_3 = insets.top;
  160.       this.dialog.setVisible(false);
  161.       this.dialog.addMouseListener(this);
  162.       if (((Applet)this).getParameter("item_text_color") != null) {
  163.          this.textColor = this.getColor("item_text_color");
  164.       } else {
  165.          this.textColor = Color.yellow;
  166.       }
  167.  
  168.       if (((Applet)this).getParameter("item_enter_text_color") != null) {
  169.          this.enterTextColor = this.getColor("item_enter_text_color");
  170.       } else {
  171.          this.enterTextColor = Color.blue;
  172.       }
  173.  
  174.       if (((Applet)this).getParameter("item_background_color") != null) {
  175.          this.backColor = this.getColor("item_background_color");
  176.       } else {
  177.          this.backColor = Color.blue;
  178.       }
  179.  
  180.       if (((Applet)this).getParameter("item_enter_background_color") != null) {
  181.          this.enterBackColor = this.getColor("item_enter_background_color");
  182.       } else {
  183.          this.enterBackColor = Color.yellow;
  184.       }
  185.  
  186.       if (((Applet)this).getParameter("item_border_color") != null) {
  187.          this.borderColor = this.getColor("item_border_color");
  188.       } else {
  189.          this.borderColor = Color.black;
  190.       }
  191.  
  192.       this.borderSize = 0;
  193.       s = ((Applet)this).getParameter("item_border_size");
  194.       if (s != null) {
  195.          this.borderSize = Integer.parseInt(s);
  196.       }
  197.  
  198.       this.pop = new MenuBar();
  199.       this.giveMenu("");
  200.       this.table = new Hashtable();
  201.       int dec = 0;
  202.       int h = 0;
  203.  
  204.       for(int i = 0; i < this.pop.getMenuCount(); ++i) {
  205.          Menu menu = this.pop.getMenu(i);
  206.          String label = ((MenuItem)menu).getLabel();
  207.          String link = ((MenuItem)menu).getActionCommand();
  208.          Item item = new Item(label, this, link, this.textColor, this.backColor, this.enterTextColor, this.enterBackColor, this.borderColor, this.borderSize, true);
  209.          item.menuitem = menu;
  210.          this.table.put(menu, item);
  211.          item.topItem = true;
  212.          this.dialog.add(item);
  213.          ((Component)item).setBounds(this.field_2 + dec, this.field_3, ((Component)item).getPreferredSize().width, ((Component)item).getPreferredSize().height);
  214.          h = ((Component)item).getPreferredSize().height;
  215.          int maxwi = this.createItems(menu, dec, h);
  216.          if (maxwi == 0) {
  217.             maxwi = ((Component)item).getPreferredSize().width;
  218.          }
  219.  
  220.          if (i == this.pop.getMenuCount() - 1) {
  221.             this.maxWidth = maxwi + dec;
  222.          }
  223.  
  224.          dec += ((Component)item).getPreferredSize().width;
  225.       }
  226.  
  227.       Item item = new Item("", this, (String)null, this.textColor, this.backColor, this.textColor, this.backColor, this.borderColor, this.borderSize, true);
  228.       item.topItem = true;
  229.       this.dialog.add(item);
  230.       ((Component)item).setBounds(this.field_2 + dec, this.field_3, this.dialogWidth - dec, ((Component)item).getPreferredSize().height);
  231.       this.dialog.setSize(this.dialogWidth, this.dialogHeight);
  232.       this.dialog.show();
  233.       if (this.sound != null) {
  234.          if (this.loopSound) {
  235.             this.sound.loop();
  236.             return;
  237.          }
  238.  
  239.          this.sound.play();
  240.       }
  241.  
  242.    }
  243.  
  244.    public int createItems(Menu menu, int x, int y) {
  245.       int decy = 0;
  246.       int maxw = 0;
  247.  
  248.       for(int i = 0; i < menu.getItemCount(); ++i) {
  249.          MenuItem menuitem = menu.getItem(i);
  250.          String label = menuitem.getLabel();
  251.          Item item = new Item(label, this, "", this.textColor, this.backColor, this.enterTextColor, this.enterBackColor, this.borderColor, this.borderSize, false);
  252.          this.dialog.add(item);
  253.          int wi = ((Component)item).getPreferredSize().width;
  254.          this.dialog.remove(item);
  255.          if (wi > maxw) {
  256.             maxw = wi;
  257.          }
  258.       }
  259.  
  260.       for(int i = 0; i < menu.getItemCount(); ++i) {
  261.          MenuItem menuitem = menu.getItem(i);
  262.          String label = menuitem.getLabel();
  263.          String link = menuitem.getActionCommand();
  264.          Item item = new Item(label, this, link, this.textColor, this.backColor, this.enterTextColor, this.enterBackColor, this.borderColor, this.borderSize, false);
  265.          item.menuitem = menuitem;
  266.          this.table.put(menuitem, item);
  267.          this.dialog.add(item);
  268.          ((Component)item).setBounds(this.field_2 + x, this.field_3 + y + decy, maxw, ((Component)item).getPreferredSize().height);
  269.          if (menuitem instanceof Menu && ((Menu)menuitem).getItemCount() != 0) {
  270.             this.createItems((Menu)menuitem, x + maxw, y + decy);
  271.             item.hasChildren = true;
  272.          }
  273.  
  274.          decy += ((Component)item).getPreferredSize().height;
  275.       }
  276.  
  277.       if (decy > this.maxHeight) {
  278.          this.maxHeight = decy;
  279.       }
  280.  
  281.       return maxw;
  282.    }
  283.  
  284.    public void showFirstChildren(MenuItem menuItem) {
  285.       Enumeration e = this.table.keys();
  286.  
  287.       while(e.hasMoreElements()) {
  288.          MenuItem menuitem = (MenuItem)e.nextElement();
  289.          Item item = (Item)this.table.get(menuitem);
  290.          if (((MenuComponent)menuitem).getParent().equals(menuItem)) {
  291.             ((Component)item).setVisible(true);
  292.          } else if (!item.topItem) {
  293.             ((Component)item).setVisible(false);
  294.          }
  295.       }
  296.  
  297.       this.isActive = true;
  298.    }
  299.  
  300.    public void showChildren(MenuItem menuItem) {
  301.       Menu parent = (Menu)((MenuComponent)menuItem).getParent();
  302.  
  303.       for(int j = 0; j < parent.getItemCount(); ++j) {
  304.          MenuItem menuitem = parent.getItem(j);
  305.          if (!menuitem.equals(menuItem) && ((Item)this.table.get(menuitem)).hasChildren) {
  306.             this.hideChildren(menuitem);
  307.          }
  308.       }
  309.  
  310.       if (((Item)this.table.get(menuItem)).hasChildren) {
  311.          Menu menuEnter = (Menu)menuItem;
  312.          if (menuEnter == null) {
  313.             return;
  314.          }
  315.  
  316.          for(int j = 0; j < menuEnter.getItemCount(); ++j) {
  317.             MenuItem menuitem = menuEnter.getItem(j);
  318.             ((Item)this.table.get(menuitem)).setVisible(true);
  319.          }
  320.       }
  321.  
  322.    }
  323.  
  324.    public void hideAllChildren() {
  325.       Enumeration e = this.table.keys();
  326.  
  327.       while(e.hasMoreElements()) {
  328.          Item item = (Item)this.table.get(e.nextElement());
  329.          if (!item.topItem && ((Component)item).isVisible()) {
  330.             ((Component)item).setVisible(false);
  331.          }
  332.       }
  333.  
  334.       this.isActive = false;
  335.    }
  336.  
  337.    public void hideChildren(MenuItem menuItem) {
  338.       Menu menuEnter = (Menu)menuItem;
  339.       if (menuEnter != null) {
  340.          for(int j = 0; j < menuEnter.getItemCount(); ++j) {
  341.             MenuItem menuitem = menuEnter.getItem(j);
  342.             if (menuitem instanceof Menu) {
  343.                this.hideChildren(menuitem);
  344.             }
  345.  
  346.             ((Item)this.table.get(menuitem)).setVisible(false);
  347.          }
  348.  
  349.       }
  350.    }
  351.  
  352.    public void stop() {
  353.       if (this.sound != null) {
  354.          this.sound.stop();
  355.       }
  356.  
  357.       this.dialog.dispose();
  358.    }
  359.  
  360.    public void getParameters() {
  361.       this.field_0 = ((Component)this).getSize().width;
  362.       this.field_1 = ((Component)this).getSize().height;
  363.       String s = ((Applet)this).getParameter("pause");
  364.       if (s != null) {
  365.          this.pause = Integer.parseInt(s);
  366.       }
  367.  
  368.       s = ((Applet)this).getParameter("frame_width");
  369.       if (s != null) {
  370.          this.dialogWidth = Integer.parseInt(s);
  371.       }
  372.  
  373.       s = ((Applet)this).getParameter("frame_height");
  374.       if (s != null) {
  375.          this.dialogHeight = Integer.parseInt(s);
  376.       }
  377.  
  378.       s = ((Applet)this).getParameter("hand");
  379.       if (s != null) {
  380.          if (s.equals("0")) {
  381.             this.hand = false;
  382.          } else {
  383.             this.hand = true;
  384.          }
  385.       }
  386.  
  387.       s = ((Applet)this).getParameter("sound_name");
  388.       if (s != null) {
  389.          this.sound = ((Applet)this).getAudioClip(((Applet)this).getCodeBase(), s);
  390.       }
  391.  
  392.       s = ((Applet)this).getParameter("loop_sound");
  393.       if (s != null) {
  394.          if (s.equals("yes")) {
  395.             this.loopSound = true;
  396.          } else {
  397.             this.loopSound = false;
  398.          }
  399.       }
  400.  
  401.       s = ((Applet)this).getParameter("clic_sound_name");
  402.       if (s != null) {
  403.          this.clicSound = ((Applet)this).getAudioClip(((Applet)this).getCodeBase(), s);
  404.       }
  405.  
  406.    }
  407.  
  408.    public Menu giveMenu(String prof) {
  409.       Menu menu = new Menu(((Applet)this).getParameter("text" + prof));
  410.       int i = 0;
  411.  
  412.       while(true) {
  413.          ++i;
  414.          String prof2 = prof + "#" + Integer.toString(i);
  415.          if (((Applet)this).getParameter("text" + prof2) == null) {
  416.             return menu;
  417.          }
  418.  
  419.          String s = ((Applet)this).getParameter("text" + prof2 + "#1");
  420.          if (s == null) {
  421.             s = ((Applet)this).getParameter("text" + prof2);
  422.             if (s.equals("-")) {
  423.                if (prof.equals("")) {
  424.                   this.pop.add(new Menu("---"));
  425.                } else {
  426.                   menu.addSeparator();
  427.                }
  428.             } else {
  429.                MenuItem menuitem = new MenuItem(((Applet)this).getParameter("text" + prof2));
  430.                menuitem.setActionCommand(((Applet)this).getParameter("link" + prof2));
  431.                if (prof.equals("")) {
  432.                   this.pop.add(new Menu(((Applet)this).getParameter("text" + prof2)));
  433.                } else {
  434.                   menu.add(menuitem);
  435.                }
  436.             }
  437.          } else if (prof.equals("")) {
  438.             this.pop.add(this.giveMenu(prof2));
  439.          } else {
  440.             menu.add(this.giveMenu(prof2));
  441.          }
  442.       }
  443.    }
  444.  
  445.    private Color getColor(String param) {
  446.       String s = ((Applet)this).getParameter(param);
  447.       if (s != null) {
  448.          if (s.substring(0, 1).equals("#")) {
  449.             s = s.substring(1);
  450.             int i = Integer.parseInt(s, 16);
  451.             return new Color(i);
  452.          } else {
  453.             return null;
  454.          }
  455.       } else {
  456.          return null;
  457.       }
  458.    }
  459.  
  460.    public URL giveURL(String url) {
  461.       try {
  462.          if (url.toUpperCase().startsWith("HTTP")) {
  463.             return new URL(url);
  464.          } else if (url.toUpperCase().startsWith("FTP")) {
  465.             int p = url.indexOf(":");
  466.             int p2 = url.indexOf(":", p + 1);
  467.             if (p2 != -1) {
  468.                url = url.substring(0, p + 3) + URLEncoder.encode(url.substring(p + 3, url.length()));
  469.             }
  470.  
  471.             p = url.indexOf("%40");
  472.             if (p != -1) {
  473.                url = url.substring(0, p) + "@" + url.substring(p + 3, url.length());
  474.             }
  475.  
  476.             return new URL(url);
  477.          } else {
  478.             return new URL(((Applet)this).getCodeBase(), url);
  479.          }
  480.       } catch (MalformedURLException e) {
  481.          System.out.println(e);
  482.          return null;
  483.       }
  484.    }
  485.  
  486.    public void mouseClicked(MouseEvent e) {
  487.    }
  488.  
  489.    public void mouseEntered(MouseEvent e) {
  490.    }
  491.  
  492.    public void mouseExited(MouseEvent e) {
  493.    }
  494.  
  495.    public void mousePressed(MouseEvent e) {
  496.       this.hideAllChildren();
  497.    }
  498.  
  499.    public void mouseReleased(MouseEvent e) {
  500.    }
  501.  
  502.    public void windowActivated(WindowEvent e) {
  503.    }
  504.  
  505.    public void windowClosed(WindowEvent e) {
  506.    }
  507.  
  508.    public void windowClosing(WindowEvent e) {
  509.       this.dialog.dispose();
  510.    }
  511.  
  512.    public void windowDeactivated(WindowEvent e) {
  513.       if (this.dialog != null) {
  514.          this.hideAllChildren();
  515.       }
  516.  
  517.    }
  518.  
  519.    public void windowDeiconified(WindowEvent e) {
  520.    }
  521.  
  522.    public void windowIconified(WindowEvent e) {
  523.    }
  524.  
  525.    public void windowOpened(WindowEvent e) {
  526.    }
  527. }
  528.